/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgBattleMorphs
    {
        private readonly Dictionary<int, CfgBattleMorphs> _dataMap;
        private readonly List<CfgBattleMorphs> _dataList;


        public TbCfgBattleMorphs(ByteBuf _buf)
        {
            //first read common data
            _TbCommonBattleMorphs _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonBattleMorphs(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgBattleMorphs>(size * 3 / 2);
            _dataList = new List<CfgBattleMorphs>(size);

            for (int i = 0; i < size; i++)
            {
                CfgBattleMorphs _v;
                _v = CfgBattleMorphs.DeserializeCfgBattleMorphs(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgBattleMorphs> DataMap => _dataMap;
        public IReadOnlyList<CfgBattleMorphs> DataList => _dataList;

        public CfgBattleMorphs Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgBattleMorphs] config not found,id:" + key.ToString());

            return null;
        }

        public CfgBattleMorphs GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "battlemorphs";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgBattleMorphs LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgBattleMorphs(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgBattleMorphs
    {
        private CfgBattleMorphs(ByteBuf _buf, _TbCommonBattleMorphs _commonData)
        {
            Id = _buf.ReadInt();
            CurHeroSkin = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; DesEntityAsset = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; MorEntityAsset = _commonData._field1[dataIndex]; }

            PostInit();
        }

        internal static CfgBattleMorphs DeserializeCfgBattleMorphs(ByteBuf _buf, _TbCommonBattleMorphs _commonData)
        {
            return new CfgBattleMorphs(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 当前皮肤ID
        /// </summary>
        public int CurHeroSkin { get; private set; }
        /// <summary>
        /// 期望皮肤资源名
        /// </summary>
        public string DesEntityAsset { get; private set; }
        /// <summary>
        /// 变身皮肤资源名
        /// </summary>
        public string MorEntityAsset { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonBattleMorphs
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal _TbCommonBattleMorphs(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
